#include <bits/stdc++.h>
#ifndef DEBUG
#define debug
#endif
using namespace std;
using i64 = int64_t;

void solve() {
  struct Point { double x, y; };
  Point p1, p2, p3, p4;
  cin >> p1.x >> p1.y;
  cin >> p2.x >> p2.y;
  cin >> p3.x >> p3.y;
  cin >> p4.x >> p4.y;
  auto get_p = [&](Point p1, Point p2, double d1, double t) {
    if (t >= d1) return p2;
    return Point{
      p1.x + (p2.x - p1.x) * t / d1,
      p1.y + (p2.y - p1.y) * t / d1
    };
  };
  auto func = [&](Point p1, Point p2, Point p3, Point p4) {
    double d1 = hypot(p1.x - p2.x, p1.y - p2.y);
    double d2 = hypot(p3.x - p4.x, p3.y - p4.y);
    double mxd = max(d1, d2);
    
    double lo = 0, hi = mxd;
    while (hi - lo > 1e-9) {
      double m1 = lo + (hi - lo) / 3;
      double m2 = hi - (hi - lo) / 3;
      Point p5 = get_p(p1, p2, d1, m1), p6 = get_p(p3, p4, d2, m1);
      Point p7 = get_p(p1, p2, d1, m2), p8 = get_p(p3, p4, d2, m2);
      double d3 = hypot(p5.x - p6.x, p5.y - p6.y);
      double d4 = hypot(p7.x - p8.x, p7.y - p8.y);
      if (d3 < d4) {
        hi = m2;
      } else {
        lo = m1;
      }
    }
    Point a = get_p(p1, p2, d1, lo), b = get_p(p3, p4, d2, lo);
    return hypot(a.x - b.x, a.y - b.y);
  };
  
  double d1 = hypot(p1.x - p2.x, p1.y - p2.y);
  double d2 = hypot(p3.x - p4.x, p3.y - p4.y);
  if (d1 > d2) {
    swap(p1, p3);
    swap(p2, p4);
    swap(d1, d2);
  }
  Point p5 = get_p(p3, p4, d2, d1);
  double ans = min(func(p1, p2, p3, p5), func(p2, p2, p5, p4));
  cout << fixed << setprecision(15) << ans << '\n';
}
int main() {
  cin.tie(0)->sync_with_stdio(0);
  int T = 1;
  cin >> T;
  for (int cas = 1; cas <= T; cas ++) {
    // cout << "Case #" << cas << ": ";
    solve();
  }
}